//package com.gxa.ehome.web.listener;
//
//import javax.servlet.ServletContext;
//import javax.servlet.ServletContextEvent;
//import javax.servlet.ServletContextListener;
//import javax.servlet.annotation.WebListener;
//import javax.servlet.http.HttpSessionAttributeListener;
//import javax.servlet.http.HttpSessionEvent;
//import javax.servlet.http.HttpSessionListener;
//import javax.servlet.http.HttpSessionBindingEvent;
//
//// 监听器向服务器中注册:
//// 1. 在web.xml 中配置
///*<listener>
//<listener-class>com.gxa.ehome.web.listener.CountListener</listener-class>
//</listener>*/
//
////2. 使用注解注册: 可以省略value, 甚至不写, 当不写的时候value就是类名
//@WebListener
//public class CountListener implements ServletContextListener,
//        HttpSessionListener, HttpSessionAttributeListener {
//
//    // Public constructor is required by servlet spec
//    public CountListener() {
//    }
//
//    // -------------------------------------------------------
//    // ServletContextListener implementation
//    // -------------------------------------------------------
//    @Override
//    public void contextInitialized(ServletContextEvent sce) {
//
//        // 从数据库中查询一部分初始化数据, 让页面访问速度加快
//        // 省份/ 城市/ 区县
//        // 所有用户数据
//
//
//        System.out.println("监听器contextInitialized初始化");
//    }
//
//    @Override
//    public void contextDestroyed(ServletContextEvent sce) {
//        System.out.println("监听器contextDestroyed摧毁操作");
//    }
//
//    int count = 0;
//    // -------------------------------------------------------
//    // HttpSessionListener implementation
//    // -------------------------------------------------------
//    @Override
//    public void sessionCreated(HttpSessionEvent se) {
//        /* Session is created. */
//
//        //当session被创建一次,就记录一个人数的+1
//        count++;
//
//        // 还要能被全局访问 ServletContext
//        ServletContext servletContext = se.getSession().getServletContext();
//        servletContext.setAttribute("count",count);
//
//        System.out.println("Session is created");
//    }
//
//    @Override
//    public void sessionDestroyed(HttpSessionEvent se) {
//        /* Session is destroyed. */
//        System.out.println("Session is destroyed");
//        count--;
//        // 还要能被全局访问 ServletContext
//        ServletContext servletContext = se.getSession().getServletContext();
//        servletContext.setAttribute("count",count);
//    }
//
//    // -------------------------------------------------------
//    // HttpSessionAttributeListener implementation
//    // -------------------------------------------------------
//
//    @Override
//    public void attributeAdded(HttpSessionBindingEvent sbe) {
//      /* This method is called when an attribute
//         is added to a session.
//      */
//    }
//
//    @Override
//    public void attributeRemoved(HttpSessionBindingEvent sbe) {
//      /* This method is called when an attribute
//         is removed from a session.
//      */
//    }
//
//    @Override
//    public void attributeReplaced(HttpSessionBindingEvent sbe) {
//      /* This method is invoked when an attibute
//         is replaced in a session.
//      */
//    }
//}
